#include "Dialogs.h"

static Dialogs *diag;

void CALLBACK Dialogs::Wnd3Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	diag->OnWnd3Proc(hwnd, msg, wParam, lParam);
}

void CALLBACK Dialogs::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	diag->OnWndProc(hwnd, msg, wParam, lParam);
}

LRESULT Dialogs::OnWnd3Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	TCHAR buff[20];
	switch(msg) {
		case WM_INITDIALOG:
			resX = resY = resZ = 0.0f;
			break;
		case WM_COMMAND:
			switch(wParam) {
				case IDOK:
					if(0 < GetDlgItemText(hwnd, IDC_EDITX, buff, 20)) {
						resX = (float)_wtof(buff);
					}
					if(0 < GetDlgItemText(hwnd, IDC_EDITY, buff, 20)) {
						resY = (float)_wtof(buff);
					}
					if(0 < GetDlgItemText(hwnd, IDC_EDITZ, buff, 20)) {
						resZ = (float)_wtof(buff);
					}
					succes = true;
				case IDCANCEL:
					EndDialog(hwnd, 0);
					return TRUE;
			}
			break;
		default:
			return FALSE;
	}
	return TRUE;
}

LRESULT Dialogs::OnWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	TCHAR buff[20];
	switch(msg) {
		case WM_INITDIALOG:
			res = 0.0f;
			break;
		case WM_COMMAND:
			switch(wParam) {
				case IDOK:
					if(0 < GetDlgItemText(hwnd, IDC_EDITBOX, buff, 20)) {
						res = (float)_wtof(buff);
					}
					succes = true;
				case IDCANCEL:
					EndDialog(hwnd, 0);
					return TRUE;
			}
			break;
		default:
			return FALSE;
	}
	return TRUE;
}

Dialogs::Dialogs(HWND parent, HINSTANCE hInstance) {
	hWndParent = parent;
	hInst = hInstance;
	diag = this;
}

void Dialogs::Init(HWND parent, HINSTANCE hInstance) {
	hWndParent = parent;
	hInst = hInstance;
}

bool Dialogs::Get3Parameters() {
	succes = false;
	DialogBox(hInst, MAKEINTRESOURCE(IDD_GET3WSP),
		hWndParent, (DLGPROC)Wnd3Proc);
	return succes;
}

bool Dialogs::GetParametr() {
	succes = false;
	DialogBox(hInst, MAKEINTRESOURCE(IDD_GETWSP),
		hWndParent, (DLGPROC)WndProc);
	return succes;
}